package cn.tedu.egaddress0805.controller;

import cn.tedu.egaddress0805.mapper.AddressMapper;
import cn.tedu.egaddress0805.pojo.dto.AddressAddPrarm;
import cn.tedu.egaddress0805.pojo.vo.AddressInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @PostMapping("add")
    public String addressAdd(@RequestBody AddressAddPrarm addressAddPrarm){
        System.out.println("添加地址" + addressAddPrarm);
        int result = addressMapper.insertAddress(addressAddPrarm);
        if (result > 0){
            return "添加地址成功";
        }
        return "添加地址失败";
    }

    @GetMapping("list")
    public List<AddressInfoVO> addressList(){
        List<AddressInfoVO> list = addressMapper.selectAddressList();
        return list;
    }

    @PostMapping("del/{addressId}")
    public String addressDel(@PathVariable Integer addressId ){
        int result = addressMapper.deleteAddressById(addressId);
        if(result > 0){
            return "删除地址成功";
        }
        return "删除地址失败";
    }

}
